<script type="text/javascript" language="javascript" charset="utf-8">
$(".header-con li a").removeClass("open-menu");
$(".header-con li #configuration").addClass("open-menu");
</script>
<div class="boxed clearfix">
  <div class="common-tit">
    <h2>商品设置</h2>
    <span>公司设置 > 课程设置</span>
  </div>
  <div class="ad-box">
    <div class="account-infor">
      <%= render partial: "company_configuration_nav" %>
      <h3>
        <em>*</em>
        <span>公司设置</span>
      </h3>
      <%= form_for(@current_company, url: update_company_name_admin_company_configurations_path, method: :post, remote: true, html: { multipart: true}) do |f| %>
        <div class="comp-set clearfix">
          <%= f.text_field :name, required: true, placeholder: "公司名称", id: "setCompany" %>
          <%= f.submit "保存", class: "set-combtn" %>
        </div>
      <% end %>
      <h3>
        <span>年终奖设置</span>
      </h3>


<%= form_for(@bonus, url: update_bonus_admin_company_configurations_path, method: :post) do |f| %>
      <div class="comp-setbox">
        <div class="comp-set">
          <div class="annual-bonus clearfix">
            <span>年终奖池:</span>
            <div class="bonus-con">
              <div class="sub-con">
                <div class="test-check">
                  <%= check_box_tag :open, "1", !@bonus.new_record?, class: "ck" %>
                  <div class="check" id="bonusCheck">
                    <span></span>
                  </div>
                </div>
              </div>
              <em>开启</em>
              <%= f.text_field :bonus_percent, required: true, placeholder: "整数", id: "bonusNum"%>
              <i>勾选后必填！</i>
            </div>
          </div>
          <div class="annual-bonus clearfix open_bonus">
            <span>奖金领取要求:</span>
            <div class="bonus-con">
              <div class="bo-con">
                <div class="sub-con">
                  <div class="test-check">
                    <%= f.check_box :one_month_sale, class: "ck" %>
                    <div class="check">
                      <span></span>
                    </div>
                  </div>
                </div>
                <b>单月业绩／课消达标</b>
                <p>单月业务达标方可领取绩效/奖金</p>
              </div>
              <div class="bo-con">
                <div class="sub-con">
                  <div class="test-check">
                    <%= f.check_box :total_sale, class: "ck" %>
                    <div class="check">
                      <span></span>
                    </div>
                  </div>
                </div>
                <b>累计业务达标</b>
                <p>当月业务未达标，产生绩效/奖金，但不可领取，直至补全未达标业绩方可发放补全未达标业绩部分，不算到当月超出目标营业额部分</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <%= submit_tag "保存", class: "bonus-sbtn" %>
  <% end %>
  </div>
</div>

<script src="/assets/js/common-list.js"></script>
<script>
$(".set-combtn").on("click", function() {
  if ($("#setCompany").val() == "") {
    $("#setCompany").css({
      "border" : "1px solid #ff5a60"
    });
  } else {
    $("#setCompany").css({
      "border" : "1px solid #9ea0b7"
    });
  }
})
$(".bonus-sbtn").on("click", function() {
  var bonusT = true;
  if ($("#bonusCheck").attr("checked") == "checked" && $("#bonusNum").val() == "") {
    bonus = false;
    $("#bonusNum").next("i").css({
      "display" : "inline"
    });
  } else {
    $("#bonusNum").next("i").css({
      "display" : "none"
    });
  }
  if (bonusT) {
    console.log("通过验证");
  };
})
</script>

<script>
  var a = <%= !@bonus.new_record? %>;
  if (a) {
    $(".open_bonus").css({
      "display" : "block"
    });
    $("#bonusNum").css({
      "display" : "inline"
    });
    $("#bonusCheck").addClass("ad-checked").children().css({
      "display": "block"
    });
    if ($(".open_bonus .ck").eq(0).attr("checked") == "checked"){
      $(".open_bonus .ck").eq(0).next().addClass("ad-checked").children().css({
        "display": "block"
      });
    }
    if ($(".open_bonus .ck").eq(1).attr("checked") == "checked"){
      $(".open_bonus .ck").eq(1).next().addClass("ad-checked").children().css({
        "display": "block"
      });
    }
  }
  else {
    $(".open_bonus").css({
      "display" : "none"
    });
    $("#bonusNum").css({
      "display" : "none"
    });
  }
$(".check").on("click",function(){
  if ($(this).hasClass("ad-checked")){
    $(this).prev().attr("check","checked");
  }
  else{
    $(this).prev().attr("check","");
  }
});

$("#bonusCheck").on("click", function(){
  if ($(this).hasClass("ad-checked")){
      $(".open_bonus").css({
        "display" : "block"
      });
      $("#bonusNum").css({
        "display" : "inline"
      });
  }
  else{
      $(".open_bonus").css({
        "display" : "none"
      });
      $("#bonusNum").css({
        "display" : "none"
      });
  }
  })
</script>
